package com.open.capacity.notice.provider.wechat;

import java.io.IOException;

import com.open.capacity.notice.provider.wechat.interactive.req.AcquireAddressListRequest;
import com.open.capacity.notice.provider.wechat.interactive.req.AcquireContactInfoRequest;
import com.open.capacity.notice.provider.wechat.interactive.req.AcquireQrCodeRequest;
import com.open.capacity.notice.provider.wechat.interactive.req.ExecWxLoginRequest;
import com.open.capacity.notice.provider.wechat.interactive.req.InitAddressListRequest;
import com.open.capacity.notice.provider.wechat.interactive.req.LoginRequest;
import com.open.capacity.notice.provider.wechat.interactive.req.SecondLoginRequest;
import com.open.capacity.notice.provider.wechat.interactive.res.AcquireAddressListResponse;
import com.open.capacity.notice.provider.wechat.interactive.res.AcquireContactInfoResonse;
import com.open.capacity.notice.provider.wechat.interactive.res.AcquireQrCodeResponse;
import com.open.capacity.notice.provider.wechat.interactive.res.ExecWxLoginResponse;
import com.open.capacity.notice.provider.wechat.interactive.res.InitAddressListResponse;
import com.open.capacity.notice.provider.wechat.interactive.res.LoginResponse;
import com.open.capacity.notice.provider.wechat.interactive.res.SecondLoginResponse;

/**
 * 
 * 微信同步请求
 */
public class SyncWechatOperations extends WechatOperations {

	public SyncWechatOperations(WechatTemplate wechatTemplate) {
		super(wechatTemplate);
	}

	/**
	 * 登录E云平台（第一步）
	 * 
	 * @param loginRequest
	 * @return
	 * @throws IOException
	 */
	public LoginResponse login(LoginRequest loginRequest) throws IOException {
		LoginResponse resp = super.post(WechatApiAddress.LOIGN_IN, false, loginRequest, LoginResponse.class,
				wechatTemplate.getWechatProperties().getHost());
		return resp;
	}

	/**
	 * 获取二维码（第二步）
	 * 
	 * @param acquireQrCodeRequest
	 * @return
	 * @throws IOException
	 */
	public AcquireQrCodeResponse aquireQrCode(AcquireQrCodeRequest acquireQrCodeRequest) throws IOException {
		AcquireQrCodeResponse resp = super.post(WechatApiAddress.ACQUIARE_QR_CODE, true, acquireQrCodeRequest,
				AcquireQrCodeResponse.class, wechatTemplate.getWechatProperties().getHost());
		return resp;
	}

	/**
	 * 执行微信登录（第三步）
	 * 
	 * @param execWxLoginRequest
	 * @return
	 * @throws IOException
	 */
	public ExecWxLoginResponse wxLogin(ExecWxLoginRequest execWxLoginRequest) throws IOException {
		ExecWxLoginResponse resp = super.post(WechatApiAddress.EXEC_WX_LOGIN, true, execWxLoginRequest,
				ExecWxLoginResponse.class, wechatTemplate.getWechatProperties().getHost());
		return resp;
	}

	/**
	 * 初始化通讯录列表（第四步）
	 * 
	 * @param initAddressListRequest
	 * @return
	 * @throws IOException
	 */
	public InitAddressListResponse initAddressList(InitAddressListRequest initAddressListRequest) throws IOException {
		InitAddressListResponse resp = super.post(WechatApiAddress.INIT_ADDRESS_LIST, true, initAddressListRequest,
				InitAddressListResponse.class, wechatTemplate.getWechatProperties().getHost());
		return resp;
	}

	/**
	 * 获取通讯录列表（第五步）
	 * 
	 * @param acquireAddressListRequest
	 * @return
	 * @throws IOException
	 */
	public AcquireAddressListResponse acquireAddressList(AcquireAddressListRequest acquireAddressListRequest)
			throws IOException {

		AcquireAddressListResponse resp = super.post(WechatApiAddress.ACQUIARE_ADDRESS_LIST, true,
				acquireAddressListRequest, AcquireAddressListResponse.class,
				wechatTemplate.getWechatProperties().getHost());
		return resp;
	}

	/**
	 * 获取联系人信息（第六步）
	 * 
	 * @param acquireAddressListRequest
	 * @return
	 * @throws IOException
	 */
	public AcquireContactInfoResonse acquireContactInfo(AcquireContactInfoRequest acquireContactInfoRequest)
			throws IOException {
		AcquireContactInfoResonse resp = super.post(WechatApiAddress.ACQUIARE_CONTACT_INFO, true,
				acquireContactInfoRequest, AcquireContactInfoResonse.class,
				wechatTemplate.getWechatProperties().getHost());
		return resp;
	}

	/**
	 * 弹框登录
	 * 
	 * @param loginRequest
	 * @return
	 * @throws IOException
	 */
	public SecondLoginResponse secondLogin(SecondLoginRequest loginRequest) throws IOException {
		SecondLoginResponse resp = super.post(WechatApiAddress.SECOND_LOGIN, true, loginRequest,
				SecondLoginResponse.class, wechatTemplate.getWechatProperties().getHost());
		return resp;
	}

}
